Add support for Broadlink BG1 devices#33399
Add support for Broadlink BG1 devices#33399b4dpxl wants to merge 3 commits intohome-assistant:devfrom b4dpxl:broadlink-bg1
Conversation
|
Hey there @Danielhiversen, @felipediel, mind taking a look at this pull request as its been labeled with a integration ( |
|
Please rebase on latest dev branch and solve the merge conflict. @felipediel do you have time to review? |
|
@MartinHjelmare Could we hold this PR a little longer? As soon as I finish implementing config entries I will come back here to help review and integrate this code. |
|
Ok. 👍 |
felipediel
left a comment
There was a problem hiding this comment.
This is not yet my final review, just a warning about a problem I recently discovered in this integration.
| try: | ||
| self._device.set_power(self._slot, packet) | ||
| except (socket.timeout, ValueError) as error: |
There was a problem hiding this comment.
This is problematic. You are not handling authentication errors and a wide variety of socket errors. If authentication fails once, the device will stop working until you restart Home Assistant.
There was a problem hiding this comment.
This was duplicated straight from the existing Switch and Slot implementations, so if this is an issue then those need fixing as well? In fact, looking (briefly) again I don't think this method is even used in this class :|
However, I am missing exception handling and retry in the _turn_on_off() method which does basically the same duty 🤦 - I'll fix that.
Re auth, the nearest thing I can see from the current implementation is that the auth method just catches the generic OSError. It would be easy enough to change socket.timeout to catch OSError instead, which should cover everything, and the polled update should handle re-authenticating. Would that work?
There was a problem hiding this comment.
Yes, this problem is real and it is everywhere. I am working on a solution that uses helper functions to handle exceptions. In the end it will be easier for you. I'll let you know when I finish.
| try: | ||
| resp = self._device.get_state() | ||
| if resp is not None: | ||
| states = {"s1": resp["pwr1"], "s2": resp["pwr2"]} # Left # Right | ||
| _LOGGER.debug(states) | ||
| except (socket.timeout, ValueError) as error: |
There was a problem hiding this comment.
as above, this logic was duplicated from existing code.
|
Hey @b4dpxl, what's up! This is the bug fix that I mentioned earlier. From now on we will use the BroadlinkDevice class as a bridge to communicate with the API. Use We still need to wait for this bug fix to be merged before I start working on the config entries. But if you adapt your code to use this pattern in the meantime it will be halfway there. |
|
@felipediel I'll take a look. So far all I've managed to do is completely screw up my local version trying to rebase it :( |
|
Replaced with #36449 |
Proposed change
This adds support for the British General Broadlink BG1 switches.
Type of change
Example entry for
configuration.yaml:Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale: